1005A - Tanya and Stairways - CodeForces Solution


implementation *800

Please click on ads to support us..

Python Code:

n = int(input())
w = [int(i) for i in input().split()]

print(w.count(1))
d = []
for i in range(1, n):
    if w[i] == 1:
        d.append(w[i-1])
d.append(w[-1])
print(*d)

C++ Code:

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;
typedef long long int lint;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
template <typename T>
using ordered_set = tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>;
#define of(m) find_by_order((m)); //random access of ordered set
#define all(v) (v).begin(),(v).end()
#define r_all(v) (v).rbegin(),(v).rend()
#define s(v) (v).size()
#define endl "\n";
#define NO cout << "NO\n";
#define YES cout << "YES\n";
#define No cout << "No\n";
#define Yes cout << "Yes\n";
#define PF push_front
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define rep(i, m) for(ll i=0;i<(m);++i)
#define rep_inv(i,m) for(ll i=(m);i>=0;--i)
#define repn(i,in, m) for(ll i=(in);i<(m);++i)
#define repn_inv(i,m,in) for(ll i=(in);i>=(m);--i)
#define clr(a) memset((a),0,sizeof(a))
#define vi vector<int>
#define vll vector<ll>

const int MOD = 1e9 + 7;
const int N = 1e6 + 5;

void print_vec(vector<ll>& v){
    for(ll i=0; i<s(v); i++) cout << v[i] << " ";
    cout << endl
}
bool is_sorted(vector<ll>& v){
    bool x = true;
    for(ll i=0; i<s(v)-1; i++) x &= (v[i] <= v[i+1]);
    return x;
}

const ll M = 27;
ll vis[M];
vector<char> g[M];
vector<char> topo;

void dfs(char u){
    vis[u-'A'] = 1;
    for(auto &v: g[u-'A']){
        if(!vis[v-'A']) dfs(v);
    }
    topo.push_back(u);
}

bool is_palindrome_s(string s) {
    string p = s;
    reverse(all(p));
    if (s == p) return true;
    else return false;
}


int main() {
    ll n; cin >> n;
    vll v(n);
    rep(i, n) cin >> v[i];
    vll ans;
    repn(i, 1, n){
        if(v[i] == 1) ans.PB(v[i-1]);
    }
    ans.PB(v[n-1]);
    cout << s(ans) << endl
    print_vec(ans);
    return 0;
}


Comments

Submit
0 Comments
More Questions

1618C - Paint the Array
469A - I Wanna Be the Guy
1294A - Collecting Coins
1227A - Math Problem
349A - Cinema Line
47A - Triangular numbers
1516B - AGAGA XOOORRR
1515A - Phoenix and Gold
1515B - Phoenix and Puzzle
155A - I_love_username
49A - Sleuth
1541A - Pretty Permutations
1632C - Strange Test
673A - Bear and Game
276A - Lunch Rush
1205A - Almost Equal
1020B - Badge
1353A - Most Unstable Array
770A - New Password
1646B - Quality vs Quantity
80A - Panoramix's Prediction
1354B - Ternary String
122B - Lucky Substring
266B - Queue at the School
1490A - Dense Array
1650B - DIV + MOD
1549B - Gregor and the Pawn Game
553A - Kyoya and Colored Balls
1364A - XXXXX
1499B - Binary Removals